package com.zkx.blogweb.entity;

/**
 * @author zkx
 */

public class CodeMsg {

    private int code;
    private String msg;

    private CodeMsg(int i, String success) {
        this.code = i;
        this.msg = success;
    }

    //通用异常
    public static CodeMsg SUCCESS = new CodeMsg(200,"success");
    public static CodeMsg SERVER_ERROR = new CodeMsg(502,"服务端异常");
    public static CodeMsg BIND_ERROR = new CodeMsg(501,"参数校验异常: %s");
    public static CodeMsg REQUEST_ILLEGAL = new CodeMsg(404,"请求非法");
    public static CodeMsg REQUEST_ERROR = new CodeMsg(401,"账号或者密码错误");

    //带动态参数的异常
    public CodeMsg fillArgs(Object... args){
        int code = this.code;
        String message = String.format(this.msg, args);
        return new CodeMsg(code,message);
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

}

